<template>
  <div class="app-container">
    <div class="item2">
      <div class="header">
        <div class="title1">
          <i class="el-icon-data-analysis"></i><span>立库WMS任务</span>
        </div>
        <div class="backB">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
        </div>
      </div>
      <div class="formCenter">
        <el-form
          :model="queryParams"
          size="large"
          :inline="true"
          ref="queryForm"
          :rules="formRules"
          label-width="90px"
        >
          <el-form-item label="任务类型:" prop="type">
            <el-select v-model="queryParams.type" placeholder="请选择" clearable>
              <el-option
              v-for="dict in dict.type.agv_tasktype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            />
            </el-select>
          </el-form-item>
          <el-form-item label="产品编码:" prop="sku">
            <el-input
              v-model="queryParams.sku"
              placeholder="请输入产品编码"
              clearable
            />
          </el-form-item>
          <el-form-item label="跟踪号:" prop="fmId">
            <el-input
              v-model="queryParams.fmId"
              placeholder="请输入跟踪号"
              clearable
            />
          </el-form-item>
          <el-form-item label="来源货位:" prop="fmLocation">
            <el-input
              v-model="queryParams.fmLocation"
              placeholder="请输入来源货位"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="medium"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-search"
              size="medium"
              @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-table
        :data="tableData"
        border
        height="680"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
      >
        <el-table-column align="center" prop="customerId" label="客户编码">
        </el-table-column>
        <el-table-column
          align="center"
          prop="sku"
          label="产品编码"
        >
        </el-table-column>
        <el-table-column align="center" prop="skudescr1" label="产品名称">
        </el-table-column>
        <el-table-column align="center" prop="edisendFlag" label="任务标记">
        </el-table-column>
        <el-table-column align="center" prop="fmId" label="跟踪号 ">
        </el-table-column>
        <el-table-column align="center" prop="fmLocation" label="来源货位">
        </el-table-column>
        <el-table-column
          align="center"
          prop="plantoLocation"
          label="目的货位"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="rq"
          label="任务生成时间"
        >
        </el-table-column>
        <el-table-column align="center" prop="type" label="任务类型">
        </el-table-column>
        <el-table-column align="center" prop="ediMsg" label="任务描述">
        </el-table-column>
        <!-- <el-table-column align="center" prop="isLock" label="是否锁定">
          <template slot-scope="scope">
            <el-select v-model="scope.row.isLock" placeholder="请选择">
              <el-option
                v-for="item in isLockOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </template>
        </el-table-column> -->
        <!-- <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleRelease(scope.row)"
              >修改锁定状态</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <div>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="handleQuery"
        />
      </div>
    </div>
    <div class="footer">
      <el-dialog
        title="操作验证"
        :visible.sync="centerDialogVisible"
        width="22%"
        left
        :close-on-click-modal="false"
      >
        <el-form
          :model="passForm"
          status-icon
          :rules="passrules"
          ref="passForm"
          label-width="60px"
          class="demo-ruleForm"
        >
          <el-form-item label="密码" prop="pass">
            <el-input
              type="password"
              v-model="passForm.pass"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit('passForm')"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { getagvTaskList } from "@/api/subSystem/continer";
import { getreviewTableSlideLocking } from "@/api/multiPass";
import { getcheckPassword } from "@/api/subSystem/continer";
export default {
    dicts: ["agv_tasktype"],
  data() {
    var passwordError = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
      } else {
        getcheckPassword(value).then((res) => {
          this.priorityNum = res.msg;
          if (res.msg == "admin") {
            callback();
          } else if (res.msg == "supper") {
            callback();
          } else if (res.msg == "false") {
            callback(new Error("密码错误"));
          }
        });
      }
    };
    return {
      // 密码验证
      centerDialogVisible: false,
      passForm: {
        pass: null,
      },
      passrules: {
        pass: [{ validator: passwordError, trigger: "blur" }],
      },
      // 总条数
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fmId: null,
        type:null,
        sku:null,
        fmLocation:null,
      },
      formRules: {
        fmId: [
          { required: false, message: "请输入跟踪号", trigger: "blur" },
        ],
      },
      tableData: [],
      loading: false,
      //是否索取传参
      isLockData: null,
      stationNoData: null,
    };
  },
  mounted() {
    this.handleQuery();
  },
  methods: {
    goBack() {
      this.$router.push("/subSystem1");
    },
    // 重置
    resetQuery(){
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          fmId: null,
          type:null,
          sku:null,
          fmLocation:null,
        };
        this.handleQuery();
    },
    handleQuery() {
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          getagvTaskList(this.queryParams).then((res) => {
            this.tableData = res.rows;
            this.total = res.total;
            this.loading = false;
          });
        }
      });
    },
    handleRelease(row) {
      this.stationNoData = row.stationNo;
      console.log("islock", row.isLock);
      if (row.isLock== "0") {
        this.isLockData = "1";
      } else if (row.isLock == "1") {
        this.isLockData = "0";
      }
    //   this.isLockData = row.isLock;
      console.log(111, row.stationNo, this.isLockData);
      this.centerDialogVisible = true;
      this.passForm.pass = null;
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // console.log(111,this.boxNumber,this.passForm.account);
          const randomMsgld = Math.floor(Math.random() * 1000000).toString();
          getreviewTableSlideLocking({
            msgId: randomMsgld,
            slideLockingDtoList: [
              {
                checkNum: this.stationNoData,
                flag: this.isLockData,
              },
            ],
          }).then((res) => {
            console.log(res);
            this.handleQuery();
          });
          this.centerDialogVisible = false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .el-icon-data-analysis::before {
    color: #00d9ff;
    margin-right: 8px;
  }
  .title1 {
    font-size: 16px;
    // margin-bottom: 15px;
    color: #808080;
    width: 170px;
    padding: 5px;
    border-bottom: 1px dotted #8ddfff;
  }
  .header {
    margin-top: -10px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-date-editor.el-input,
    .el-date-editor.el-input__inner {
      width: 220px;
      margin-right: 20px;
    }

    .backB {
      cursor: pointer;

      img {
        width: 20%;
      }
    }
  }
  .formCenter {
    height: 62px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
  }
  .footer {
    margin-top: 20px;
    width: 100%;
    min-height: 200px;
  }
}
</style>